package com.me.crgame.escenas.intro;

import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.me.crgame.core.ActorTouchListener;
import com.me.crgame.core.Escena;
import com.me.crgame.core.EnumEscena;
import com.me.crgame.core.EnumTransicion;
import com.me.crgame.core.actores.ActorButton;
import com.me.crgame.core.actores.ActorButtonCircular;
import com.me.crgame.core.actores.ActorLabel;


public class EscenaIntro extends Escena implements ActorTouchListener{

	ActorLabel planeta;
	float j;
	ActorLabel estrella;
	ActorButtonCircular start;
	boolean subir;
	

	public EscenaIntro() {
		super();
		
		super.setBackground("data/sistema_menus/pantalla_inicial/fondoIntro.jpg");
		
		j=0;
		subir=true;
		
		estrella = new ActorLabel("data/sistema_menus/pantalla_inicial/star.png");
		estrella.setX(750);
		estrella.setY(300);
		estrella.habilitarRotarEscalar(true);
		estrella.setScale(0.5f);
		
		planeta = new ActorLabel("data/sistema_menus/pantalla_inicial/planeta.png");
		planeta.setX(325);
		planeta.setY(-600);
		planeta.habilitarRotarEscalar(true);
		planeta.setScale(1.5f);
		
		
		start = new ActorButtonCircular("data/sistema_menus/pantalla_inicial/play.png", this);
		start.habilitarRotarEscalar(true);
		start.setX(510);
		start.setY(130);
		start.setScale(0.5f);
		
		super.addActor(start);
		super.addActor(estrella);
		super.addActor(planeta);
	}

	@Override
	protected void empiezaLaEscena() {
		//Aqui van las actions...
		super.setScale(1f);
	}

	@Override
	protected void empiezaLaEscena(int transitionMode) {
	}

	@Override
	protected void terminaLaEscena() {
	}

	@Override
	protected void pause(boolean gamePaused) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void update(float deltaTime) {
		
		planeta.rotate((float) (Math.PI-3));
		start.rotate((float) -(Math.PI-2));
		estrella.rotate((float) (Math.PI-1));
		
		if(subir)
			j++;
		else 
			j--;
		
		if(j==199)
			subir=false;
		if(j==1)
			subir=true;
		
		estrella.getColor().a = j;

	}
	
	
	@Override
	public boolean touchDown(ActorButton actor, float x, float y, int pointer) {

		if (actor == start) {
			activarVibracion(VIBRACIOM_CORTA);
			sonidoBotonPulsado.play();

			//DIFUMINACION CON REBOTE
			//super.addAction(Actions.sequence(Actions.rotateTo(20f,0.2f),Actions.alpha(0.9f),Actions.rotateTo(15f,0.2f),Actions.alpha(0.8f),Actions.rotateTo(30f,0.2f),Actions.alpha(0.7f),Actions.rotateTo(25,0.2f),Actions.alpha(0.6f),Actions.rotateTo(40f,0.2f),Actions.alpha(0.5f),Actions.rotateTo(30f,0.2f),Actions.alpha(0.4f),Actions.rotateTo(50f,0.2f),Actions.alpha(0.3f),Actions.rotateTo(40f,0.2f),Actions.alpha(0.2f),Actions.rotateTo(60f,0.2f),Actions.alpha(0.1f),Actions.rotateTo(50f,0.2f),Actions.rotateTo(180f,0.7f)));
			
			//DIFUMINACION (personalizable)
			//	super.addAction(Actions.sequence(Actions.rotateTo(0f,0.2f),Actions.alpha(0.9f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.8f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.7f),Actions.rotateTo(0,0.2f),Actions.alpha(0.6f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.5f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.4f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.3f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.2f),Actions.rotateTo(0f,0.2f),Actions.alpha(0.1f),Actions.rotateTo(0f,0.2f),Actions.alpha(0f),Actions.rotateTo(0f,0.7f)));

			//REBOTE
			//super.addAction(Actions.sequence(Actions.rotateTo(20f,0.2f),Actions.rotateTo(15f,0.2f),Actions.rotateTo(30f,0.2f),Actions.rotateTo(25,0.2f),Actions.rotateTo(40f,0.2f),Actions.rotateTo(30f,0.2f),Actions.rotateTo(50f,0.2f),Actions.rotateTo(40f,0.2f),Actions.rotateTo(60f,0.2f),Actions.rotateTo(50f,0.2f),Actions.rotateTo(180f,0.7f)));
			
			//MOVIMIENTO REDUCTOR
			//super.addAction(Actions.sequence(Actions.moveTo(100f,100f),Actions.delay(0.3f),Actions.scaleTo(0.8f,0.8f),Actions.moveTo(200f,400f),Actions.delay(0.3f),Actions.scaleTo(0.6f,0.6f),Actions.moveTo(200f,200f),Actions.delay(0.3f),Actions.scaleTo(0.4f,0.4f),Actions.moveTo(300f,300f),Actions.delay(0.3f),Actions.scaleTo(0.2f,0.2f),Actions.moveTo(200f,200f),Actions.delay(0.3f),Actions.scaleTo(0.1f,0.1f),Actions.moveTo(250f,250f),Actions.delay(0.3f),Actions.scaleTo(0f,0f)));
			
			//DIFUMINACION ESTANDAR
			//	super.addAction(Actions.fadeOut(3f));
			
			//REDUCCION CON ROTACION
			//	super.addAction(Actions.sequence(Actions.moveTo(450f,100f),Actions.rotateBy(100f),Actions.delay(0.2f),Actions.scaleTo(0.8f,0.8f),Actions.moveTo(450f,200f),Actions.rotateBy(100f),Actions.delay(0.2f),Actions.scaleTo(0.6f,0.6f),Actions.moveTo(450f,250f),Actions.rotateBy(100f),Actions.delay(0.2f),Actions.scaleTo(0.4f,0.4f),Actions.moveTo(450f,300f),Actions.rotateBy(100f),Actions.delay(0.2f),Actions.scaleTo(0.2f,0.2f),Actions.moveTo(450f,400f),Actions.rotateBy(100f),Actions.delay(0.2f),Actions.scaleTo(0.1f,0.1f),Actions.moveTo(450f,450f),Actions.rotateBy(100f),Actions.delay(0.2f),Actions.scaleTo(0f,0f)));

			this.habilitarRotarEscalar(true);
			super.addAction(Actions.parallel(Actions.rotateBy(360f,3f),Actions.scaleTo(0.0f, 0.0f,3f, Interpolation.exp10)));
			
			cambiarEscena(EnumEscena.PERFILES, EnumTransicion.X);
			
		}
		// se retorna true si se quiere que los eventos drag y up
		return true;				// sean atendidos
	}

	@Override
	public void touchDragged(ActorButton actor, float x, float y, int pointer) {
	}

	@Override
	public void touchUp(ActorButton actor, float x, float y, int pointer) {
	}

}
